package com.hup.winHolderService.controller;

import com.hup.winHolderService.model.AppInfo;
import com.hup.winHolderService.service.MainService;
import com.hup.winHolderService.service.ScheduleService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hugan
 * @date 2020/2/29
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class MainController {

    private final MainService mainService;
    private final ScheduleService scheduleService;

    //状态管理 ===================
    @GetMapping("/exit")
    public ResponseEntity<Void> exit() {
        mainService.exit();
        return ResponseEntity.ok().build();
    }

    @GetMapping("/appInfo")
    public ResponseEntity<AppInfo> appInfo() {
        return ResponseEntity.ok(mainService.appInfo());
    }

    /**
     * 静音
     */
    @GetMapping("/setMute/{isMute}")
    public ResponseEntity<Void> setMute(@PathVariable("isMute") boolean isMute) {
        mainService.setMute(isMute);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/setVolume/{volume}")
    public ResponseEntity<Void> setVolume(@PathVariable("volume") int volume) {
        mainService.setVolume(volume);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/muteAndLock")
    public ResponseEntity<Void> muteAndLock() {
        mainService.muteAndLock();
        return ResponseEntity.ok().build();
    }

    @GetMapping("/lock")
    public ResponseEntity<Void> lock() {
        mainService.lock();
        return ResponseEntity.ok().build();
    }

    @GetMapping("/lockPlan/{minute}")
    public ResponseEntity<Void> lockPlan(@PathVariable("minute") int minute) {
        scheduleService.lockPlan(minute);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/lockPlanCancel")
    public ResponseEntity<Void> lockPlanCancel() {
        scheduleService.lockPlanCancel();
        return ResponseEntity.ok().build();
    }

    @GetMapping("/setEnableKillWinUpdateTask/{enable}")
    public ResponseEntity<Void> setEnableKillWinUpdateTask(@PathVariable("enable") boolean enable) {
        scheduleService.setEnableKillWinUpdateTask(enable);
        return ResponseEntity.ok().build();
    }

    //电源管理 ===================
    @GetMapping("/sleep")
    public ResponseEntity<Void> sleep() {
        mainService.sleep();
        return ResponseEntity.ok().build();
    }

    @GetMapping("/shutdownCancel")
    public ResponseEntity<Void> shutdownCancel() {
        mainService.shutdownCancel();
        return ResponseEntity.ok().build();
    }

    @GetMapping("/shutdown/{minute}")
    public ResponseEntity<Void> shutdown(@PathVariable("minute") int minute) {
        mainService.shutdown(minute);
        return ResponseEntity.ok().build();
    }

    //外部程序
    @GetMapping("/runExternalApp/{name}")
    public ResponseEntity<Void> runExternalApp(@PathVariable("name") String name) {
        mainService.runExternalApp(name);
        return ResponseEntity.ok().build();
    }

}
